package com.javaEE.gamepigeon.controller;


import com.javaEE.gamepigeon.entity.Experience;
import com.javaEE.gamepigeon.service.ExperienceService;
import com.javaEE.gamepigeon.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "经验与评论接口")
@RestController
@RequestMapping("/experience")
public class ExperienceController {

    @Autowired
    ExperienceService experienceService;


    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId",value = "用户ID",paramType = "query"),
            @ApiImplicitParam(name = "comId",value = "比赛的ID",paramType = "query"),
            @ApiImplicitParam(name = "commentDetail",value = "评论内容",paramType = "query")
    })
    @GetMapping("/add")
    @ApiOperation("发表评论")
    public Result addExperience(Integer userId, Integer comId, String commentDetail){
        if(experienceService.addExperience(userId,comId,commentDetail)){
            return Result.success("添加成功！");
        }else {
            return Result.error("添加失败");
        }
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "commentId",value = "评论ID",paramType = "query"),
    })
    @GetMapping("/delete")
    @ApiOperation("删除评论")
    public Result deleteExperience(Integer commentId){
        if(experienceService.deleteExperience(commentId)){
            return Result.success("ok");
        }else {
            return Result.error("删除错误");
        }
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "comId",value = "竞赛的ID",paramType = "query")
    })
    @GetMapping("/query")
    @ApiOperation("查询对应竞赛ID下的所有评论")
    public List<Experience> queryExperience(Integer comId){
        return experienceService.queryExperience(comId);
    }


}
